<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Models\User as user;
use Auth;
use Illuminate\Support\Facades\Hash;
class LoginController extends Controller
{
    
     //打开网站登录页 
     public function login()
     {
            return view('admin.login');
     }
     
     
     
    //待优化  
    public  function dologin(Request $request)
    {
        $email = $request->input("email");
        $password = $request->input("password");
        $user = \DB::table("users")->where("email",$email)->first();
        //如果不为空 
        if(!empty($user)){
            //密码是否相等
            if(md5($password)==$user->password){
                
                $nickname = session('nickname',$user->name);
               
                session(['users'=>$user->name]);
                 session(['user_id'=>$user->id]);
                return redirect("index");
             
            }else{
                 return back()->with("msg","密码不正确");
                
            }
        }else{
            return back()->with("msg","用户名不正确");
          
        }
    }
    
    
    public  function logout(Request $request)
    {
       $request->session()->forget('users');
       return redirect('/');
    }
    
    
    
}